package com.ocean.elasticSearch.service.impl;
import com.ocean.elasticSearch.constant.PageConstant;
import com.ocean.elasticSearch.dao.ElasticLogRepository;
import com.ocean.elasticSearch.entity.Pages;
import com.ocean.elasticSearch.entity.SysLogs;
import com.ocean.elasticSearch.service.LogService;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.List;

/**
 * @version 1.0
 * @className: LogServiceImpl
 * @description: TODO
 * @author: lxq
 * @date: 2021/4/15
 **/
@Component
public class LogServiceImpl implements LogService {
    private static final Logger logger = LoggerFactory.getLogger(LogServiceImpl.class);

    @Autowired
    private ElasticLogRepository elasticLogRepository;

    @Override
    public void saveLog(SysLogs log) {
        elasticLogRepository.save(log);
    }

    @Override
    public Iterator<SysLogs> findAll() {
        return elasticLogRepository.findAll().iterator();
    }

    @Override
    public Page<SysLogs> searchLogPage(Integer pageNumber, Integer pageSize, Integer platFrom, String searchContent) {
        //设置排序
        return elasticLogRepository.findAll(PageRequest.of(0, 20));
    }

}